<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\permissions;

class Tabbar
{
    public static function all($uniacid, int $user_id)
    {
        $diy = \app\diy\model\DiyModel::where([["uniacid", "=", $uniacid], ["status", "=", 1]])->find();
        if(empty($diy)) {
            return [];
        }
        $diy_tabbar = json_decode($diy["tabbar"], true);
        $denyTabbarKeys = [];
        $permissions = config("permissions");
        foreach ($permissions as $permissionClass) {
            if(!is_subclass_of($permissionClass, "longbingcore\\permissions\\PermissionAbstract")) {
            } else {
                $permission = new $permissionClass($uniacid, $user_id);
                if(!$permission->cAuth($user_id) && !empty($permission->tabbarKey)) {
                    $denyTabbarKeys[] = $permission->tabbarKey;
                }
            }
        }
        foreach ($diy_tabbar["list"] as $k => $tabbar) {
            if(in_array($tabbar["key"], $denyTabbarKeys)) {
                unset($diy_tabbar["list"][$k]);
            }
        }
        return $diy_tabbar;
    }
    public static function allForDiySelect($uniacid)
    {
        $diy_tabbar = [];
        $adminModelListInfo = config("app.AdminModelList");
        $saas_auth_admin_model_list = $adminModelListInfo["saas_auth_admin_model_list"];
        foreach ($saas_auth_admin_model_list as $key => $item) {
            $className = "Permission" . ucfirst($key);
            $permissionPath = APP_PATH . $key . "/info/" . $className . ".php";
            if(file_exists($permissionPath) && (require_once $permissionPath)) {
                $permissionClassName = "app\\" . $key . "\\info\\" . $className;
                $permission = new $permissionClassName($uniacid, $item);
                if($permission->pAuth() && !empty($permission->adminMenuKey)) {
                    $diyTabbarPath = APP_PATH . $key . "/info/DiyTabbar.php";
                    if(file_exists($diyTabbarPath)) {
                        $tabbar = (include_once $diyTabbarPath);
                        $diy_tabbar = array_merge($diy_tabbar, $tabbar);
                    }
                }
            }
        }
        $data["list"] = $diy_tabbar;
        $data["color"] = "#5d6268";
        $data["selectedColor"] = "#19c865";
        $data["backgroundColor"] = "#fff";
        $data["borderStyle"] = "white";
        return $data;
    }
    public static function getAuthDefultTabbar($data)
    {
        $url = config("app.AdminModelList")["diy_default_data"]["tabbar"];
        $url = json_decode($url, true);
        foreach ($url["list"] as $k => $v) {
            if(!in_array($v["key"], $data)) {
                unset($url["list"][$k]);
            }
        }
        $url["list"] = array_values($url["list"]);
        return $url;
    }
    public static function getAuthDefultPage($data)
    {
        $url = config("app.AdminModelList")["diy_default_data"]["page"];
        $url = json_decode($url, true);
        foreach ($url as $k => $v) {
            if(!in_array($k, $data)) {
                unset($url[$k]);
            }
        }
        return $url;
    }
    public function getAuthList($uniacid)
    {
        $denyAdminMenuKeys = [];
        if(empty($uniacid)) {
            return $denyAdminMenuKeys;
        }
        $adminModelListInfo = config("app.AdminModelList");
        $saas_auth_admin_model_list = $adminModelListInfo["saas_auth_admin_model_list"];
        foreach ($saas_auth_admin_model_list as $key => $item) {
            $className = "Permission" . ucfirst($key);
            $permissionPath = APP_PATH . $key . "/info/" . $className . ".php";
            if(file_exists($permissionPath) && (require_once $permissionPath)) {
                $permissionClassName = "app\\" . $key . "\\info\\" . $className;
                $permission = new $permissionClassName($uniacid, $item);
                if($permission->pAuth() && !empty($permission->adminMenuKey)) {
                    $denyAdminMenuKeys[$key] = $item;
                }
            }
        }
        return $denyAdminMenuKeys;
    }
}

?>